package org.jtrace;

import org.jtrace.geometry.GeometricObject;
import org.jtrace.primitives.ColorRGB;
import org.jtrace.primitives.Point3D;
import org.jtrace.primitives.ReflectanceCoefficient;
import org.jtrace.primitives.Vector3D;

public class CylindricalTexture extends Texture {

	public CylindricalTexture(String texturePath, ColorRGB color, ReflectanceCoefficient kAmbient, ReflectanceCoefficient kDiffuse) {
		super(texturePath, color, kAmbient, kDiffuse);
	}

	public CylindricalTexture(String texturePath, ColorRGB color, ReflectanceCoefficient kAmbient, ReflectanceCoefficient kDiffuse, ReflectanceCoefficient kSpecular) {
		super(texturePath, color, kAmbient, kDiffuse, kSpecular);
	}

	@Override
	public ColorRGB getColor(Hit hit, Jay jay, GeometricObject object) {
		Point3D hitPoint = hit.getPoint(jay);
		double x = hitPoint.getX();
		double y = hitPoint.getY();
		double z = hitPoint.getZ();
		
		double h = object.getHeight();
		
		double v = Math.abs(Math.atan(x/z));
		double u = Math.abs(y/h);
		
		System.out.println(u + " " + v);
		return new ColorRGB(img.getRGB((int) (u * img.getWidth()), (int) (v * img.getHeight())));
	}

}
